/*---------------------------------------------------------------
 * Confidential and Proprietary
 * Copyright 2007 Hewlett-Packard Development Company, L.P.
 * All Rights Reserved
 *---------------------------------------------------------------
 * Project Name    : SPF
 * Sub Project Name: SPF
 *
 * Class Name      : SystemParams
 * Purpose         : 
 *---------------------------------------------------------------
 * Modification Log
 * Date         Ver. #      Programmer       Description
 *
 * 2006-3-24    1.0          zhangminjin          Initial
 *---------------------------------------------------------------
 */
package com.erdos.common.util;

import java.util.ResourceBundle;

/**
 * <p>System parameters</p>
 * @version     1.0     <br/>
 * @author      zhangminjin    
 */

public class SystemParams {
	public final static ResourceBundle rb = getResourceBundle();
    
    public final static String ADMIN_ROLE = getProperty("ADMIN_ROLE_NAME");

//  Mail Configuration
	public static final String MAIL_SESSION = getProperty("MAIL.SESSION");

	public static final String MAIL_TRANSPORT = getProperty("MAIL.TRANSPORT");

	public static final String MAIL_ENCODING = getProperty("MAIL.ENCODING");

	public static final String MAIL_CONTENTTYPE = getProperty("MAIL.CONTENTTYPE");

    // default cache size for usergroup cache
    public static final int USERGROUP_CACHE_SIZE = getIntProperty("USERGROUP_CACHE_SIZE");
    
    public static final boolean REQUIRE_AUTH = getBooleanProperty("REQUIRE_AUTH");
    
    public static final String SYSTEM_ERROR_PAGE = getProperty("SYSTEM_ERROR_PAGE");
    
    public static final String ERROR_ALERT_PAGE = getProperty("ERROR_ALERT_PAGE");
    
	public static int getIntProperty(String propertyName) {
		String temp = getProperty(propertyName).trim();
		int result = -1;
		try {
			result = Integer.valueOf(temp).intValue();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static boolean getBooleanProperty(String propertyName) {
		Boolean ret = Boolean.FALSE;
		try {
			String value = rb.getString(propertyName);
			if(value==null){
				value = "false";
			}
			ret = Boolean.valueOf(value);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret.booleanValue();
	}
	
	public static String getProperty(String propertyName) {
		String ret = null;
		try {
			ret = rb.getString(propertyName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}

	public static double getDoubleProperty(String propertyName) {
		String temp = getProperty(propertyName).trim();
		double result = -1;
		try {
			result = Double.valueOf(temp).doubleValue();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return result;
	}
    
    public static float getFloatProperty(String propertyName) {
        String temp = getProperty(propertyName).trim();
        float result = -1;
        try {
            result = Float.valueOf(temp).floatValue();
        } catch (Exception e) {
            e.printStackTrace();
        } 
        return result;
    }    

	private static ResourceBundle getResourceBundle() {
		ResourceBundle rb =null;
		try {
			rb = ResourceBundle.getBundle("SystemParams");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rb;
	}

}
